package com.eaoa.tag;

import java.util.ArrayList;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.taglib.TagUtils;

import com.eaoa.utils.ConstantsParameterContainer;
import com.eaoa.vo.pub.PubAccount;
import com.stony.core.util.CoreUtils;

public class LabelValueParameterCollectionTag extends TagSupport {

	protected String id = null;

	private String parameter = null;

	private String name = null;

	private String property = null;

	private String parameter1 = null;

	private String name1 = null;

	private String property1 = null;

	protected String labelvalue = null;

	protected String scope = null;

	public int doEndTag() throws JspException {

		if (name != null) {
			try {
				parameter = CoreUtils.formatString(TagUtils.getInstance()
						.lookup(pageContext, name, property, scope));
			} catch (JspException e) {
				pageContext.setAttribute(id, new ArrayList(),
						PageContext.PAGE_SCOPE);
				return (EVAL_PAGE);
			}

			if (StringUtils.isBlank(parameter)) {
				pageContext.setAttribute(id, new ArrayList(),
						PageContext.PAGE_SCOPE);
				return (EVAL_PAGE);
			}

		}

		if (name1 != null) {
			try {
				parameter1 = CoreUtils.formatString(TagUtils.getInstance()
						.lookup(pageContext, name1, property1, scope));
			} catch (JspException e) {
				pageContext.setAttribute(id, new ArrayList(),
						PageContext.PAGE_SCOPE);
				return (EVAL_PAGE);
			}

		}

		PubAccount employee = (PubAccount) TagUtils.getInstance().lookup(
				pageContext, "Employee", "session");

		ConstantsParameterContainer parameterContainer = new ConstantsParameterContainer(
				labelvalue, parameter, parameter1, employee);

		parameterContainer.execute();

		pageContext.setAttribute(id, parameterContainer.getResults(),
				PageContext.PAGE_SCOPE);

		return (EVAL_PAGE);
	}

	public void release() {

		id = null;
		labelvalue = null;
		scope = null;
		parameter = null;

	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getLabelvalue() {
		return labelvalue;
	}

	public void setLabelvalue(String labelvalue) {
		this.labelvalue = labelvalue;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public String getParameter() {
		return parameter;
	}

	public void setParameter(String parameter) {
		this.parameter = parameter;
	}

	public String getName1() {
		return name1;
	}

	public void setName1(String name1) {
		this.name1 = name1;
	}

	public String getProperty1() {
		return property1;
	}

	public void setProperty1(String property1) {
		this.property1 = property1;
	}

}
